unit uDBEngine;

interface

uses
  ASGSQLite3, DB;
  
type

  TDBEngine = class
  private
    FDB: TASQLite3DB;
    FQuery: TASQLite3Query;
  public
    constructor Create;
    destructor Destroy; override;
    function ExecuteQuery(const strSql: string): Integer;
    property Query: TASQLite3Query read FQuery;
  end;

var
  G_DBEngine: TDBEngine;
implementation

uses
  SysUtils;
  
{ TDBEngine }

constructor TDBEngine.Create;
begin
  inherited;
  FDB := TASQLite3DB.Create(nil);
  FDB.Database := ExtractFilePath(ParamStr(0)) + 'CG\1\cityguide.sqlite';
  FQuery := TASQLite3Query.Create(nil);
  FQuery.Connection := FDB;
  FDB.Open;  
end;

destructor TDBEngine.Destroy;
begin
  FQuery.Free;
  FDB.Free;
  inherited;
end;

function TDBEngine.ExecuteQuery(const strSql: string): Integer;
begin
  try
    FQuery.Close;
    FQuery.SQL.Text := strSql;
    FQuery.Open;
    result := FQuery.RecordCount;
  except
    Result := -1;
  end;
end;

end.
